package test;
import java.util.InputMismatchException;
import java.util.Scanner;

public class MyArray{
    public int[] arr;
    public int arrSize;
    public void getArray() {
        System.out.println("请输入数组中的数");
        System.out.println("以-1为结束");
        Scanner scanner = new Scanner(System.in);
        try {
            int num = scanner.nextInt();
            int i = 0;
            while(num != -1) {
                arr[i++] = num;
                num = scanner.nextInt();
                this.arrSize++;
            }
        }catch(InputMismatchException e) {
            System.out.println("输入错误,停止输入");
        }
    }
    public int getNum(int n) throws OutOfBoundsException{
        if(n >= this.arrSize) {
            throw new OutOfBoundsException();
        }
        return this.arr[n];
    }
    public MyArray() {
        this.arr = new int[20];
        this.arrSize = 0;
    }
}
